package org.jawa.learning.dao;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jawa.core.cache.CacheFactory;
import org.jawa.core.exception.InitializationException;
import org.jawa.core.util.JawaGlobals;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;

/**
 * Base class for running DAO tests.
 * 
 * @author mraible
 */
@ContextConfiguration(locations = { "classpath:/applicationContext-resources.xml",
		"classpath:/applicationContext-dao.xml", "classpath*:/applicationContext.xml",
		"classpath:**/applicationContext*.xml" })
public abstract class BaseDaoTestCase extends AbstractTransactionalJUnit4SpringContextTests {
	/**
	 * Log variable for all child classes. Uses LogFactory.getLog(getClass())
	 * from Commons Logging
	 */
	protected final Log log = LogFactory.getLog(getClass());

	/**
	 */
	public BaseDaoTestCase() {
		// 设置系统配置文件
		JawaGlobals.setConfigName("/conf/learning.xml");

		try {
			CacheFactory.initialize();
		} catch (InitializationException e) {
			log.error("缓存初始化出错!");
		}

	}

	protected DataSource dataSource;

	@Override
	@Autowired
	public void setDataSource(DataSource dataSource) {
		super.setDataSource(dataSource);
		this.dataSource = dataSource;
	}
}
